HTMLify
Valid Anagram.cpp(using unordered Set)
Views: 1 | Author: cody
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | class Solution {
public:
bool isAnagram(string s, string t) {
unordered_set<char>set;
for(int i =0; i<s.length(); i++){
if(set[i]==0){
set.insert(s[i]);
}
else{
set.insert(s[i]);
}
}
unordered_set<char>map;
for(int i = 0; i<t.length(); i++){
if(map[i]==0){
map.insert(t[i]);
}
else{
map.insert(t[i]);
}
}
if(set == map){
return true;
}
else{
return false;
}
}
};
|